package com.ofhb.webapp.server.impl;

import javax.ejb.EJB;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.ofhb.bean.DataWriterBean;
import com.ofhb.entities.HallEntity;
import com.ofhb.entities.UserEntity;
import com.ofhb.webapp.client.services.DataWriterService;
import com.ofhb.webapp.server.utils.OfhbUtils;
import com.ofhb.webapp.shared.dto.HallDTO;
import com.ofhb.webapp.shared.dto.UserDTO;


public class DataWriterServiceImpl extends RemoteServiceServlet implements DataWriterService {

    private static final long serialVersionUID = 7347427706338455185L;

    @EJB
    DataWriterBean dataWriterBean;
    
    @Override
    public UserDTO save(UserDTO userDTO) throws IllegalArgumentException {
    	try {
    		UserEntity userEntity = new UserEntity();
            	OfhbUtils.copyClass(userDTO, userEntity);
            	userEntity = dataWriterBean.save(userEntity);
            	userDTO.setId(userEntity.getId());
        	return userDTO;
		} catch (Exception e) {
			System.err.println(e.getLocalizedMessage());
		}
    	return null;
    }

	@Override
	public HallDTO save(HallDTO hallDTO) throws IllegalArgumentException {

		try {
    		HallEntity hallEntity = new HallEntity();
            	OfhbUtils.copyClass(hallDTO, hallEntity);
            	hallEntity = dataWriterBean.save(hallEntity);
            	hallDTO.setId(hallEntity.getId());
        	return hallDTO;
		} catch (Exception e) {
			System.err.println(e.getLocalizedMessage());
		}
		return null;
	}
}
